﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="isikuAndmed", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(IsikuAndmed))]
    public class IsikuAndmedSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IIsikuAndmed clazz;
        
        public IsikuAndmedSerializer(IIsikuAndmed clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("nimi");
            if (clazz.Nimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("eesnimi");
            if (clazz.Eesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Eesnimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.Id))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("kood");
            if (clazz.Kood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("isikType");
            if (clazz.IsikType!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikType))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikType");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("riik");
            if (clazz.Riik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Riik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Riik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("indeks");
            if (clazz.Indeks!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Indeks))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Indeks");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("aadress");
            if (clazz.Aadress!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Aadress))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Aadress");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("ehak");
            if (clazz.Ehak!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Ehak))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Ehak");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("muulane");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Muulane))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("mkuup");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.Mkuup))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="nimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>nimi");
                }
                clazz.Nimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>nimi", Reader.LocalName);
            }
            if (Reader.LocalName=="eesnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>eesnimi");
                }
                clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("eesnimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>eesnimi", Reader.LocalName);
            }
            if (Reader.LocalName=="id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>id");
                }
                clazz.Id = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>id", Reader.LocalName);
            }
            if (Reader.LocalName=="kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>kood");
                }
                clazz.Kood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>kood", Reader.LocalName);
            }
            if (Reader.LocalName=="isikType") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>isikType");
                }
                clazz.IsikType = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isikType")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>isikType", Reader.LocalName);
            }
            if (Reader.LocalName=="riik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>riik");
                }
                clazz.Riik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("riik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>riik", Reader.LocalName);
            }
            if (Reader.LocalName=="indeks") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>indeks");
                }
                clazz.Indeks = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("indeks")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>indeks", Reader.LocalName);
            }
            if (Reader.LocalName=="aadress") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>aadress");
                }
                clazz.Aadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aadress")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>aadress", Reader.LocalName);
            }
            if (Reader.LocalName=="ehak") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>ehak");
                }
                clazz.Ehak = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ehak")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>ehak", Reader.LocalName);
            }
            if (Reader.LocalName=="muulane") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>muulane");
                }
                clazz.Muulane = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("muulane")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>muulane", Reader.LocalName);
            }
            if (Reader.LocalName=="mkuup") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikuAndmed>mkuup");
                }
                clazz.Mkuup = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("mkuup")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikuAndmed>mkuup", Reader.LocalName);
            }
        }
    }
}
